package com.ocom.payconfig.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.EntityKitchenPrtScheme;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.KitchenPrinter.KitchenPrinterDeleteRequest;
import com.ocom.common.request.payconfig.KitchenPrinter.KitchenPrinterSchemeRequest;
import com.ocom.common.request.payconfig.KitchenPrinter.dto.KitchenPrtListDto;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.KitchenPrtSchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class KitchenPrtSchemeController {

    @Autowired
    private KitchenPrtSchemeService kitchenPrtSchemeService;

    @PostMapping(PayConfigUrl.Url_setKitchenPrtScheme)
    public Result setKitchenPrtScheme(@RequestBody KitchenPrinterSchemeRequest request) {

        EntityKitchenPrtScheme kitchenPrtScheme = JSON.parseObject(JSON.toJSONString(request), EntityKitchenPrtScheme.class);
        kitchenPrtScheme.setKPrtId(request.getPrtId());

        Boolean result = kitchenPrtSchemeService.saveScheme(request.getComId(), kitchenPrtScheme);
        if (!result) {
            return ResultUtil.error(ResultEnum.Err_4002, "本地修改失败！");
        }

        return ResultUtil.success();
    }
}
